package com.example.livereplay.common.controller;

import com.example.livereplay.common.model.enity.SysAttachment;
import com.example.livereplay.common.model.request.LoginByPhoneRequest;
import com.example.livereplay.common.model.request.LoginByUserNameRequest;
import com.example.livereplay.common.model.request.UpdatePasswordRequest;
import com.example.livereplay.common.model.request.UserRegisterRequest;
import com.example.livereplay.common.service.SysUserService;
import com.wingice.common.web.ErrorCodeInfo;
import com.wingice.common.web.ResultBean;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import javax.validation.Valid;

@RestController
@RequestMapping("/sysUser")
@Tag(name = "用户管理")
public class SysUserController {
    @Resource
    private SysUserService sysUserService;
    @PostMapping("/userUpdatePassword")
    @Operation(summary = "用户修改密码")
    public ResultBean<Boolean> userUpdatePassword(@RequestBody @Valid UpdatePasswordRequest updatePasswordRequest) {
        return ResultBean.restResult(sysUserService.userUpdatePassword(updatePasswordRequest), ErrorCodeInfo.OK);
    }

    @Operation(summary = "用户注册")
    @PostMapping("/userRegister")
    public ResultBean<Boolean> userRegister(@RequestBody @Valid UserRegisterRequest userRegisterRequest){
        return ResultBean.restResult(sysUserService.userRegister(userRegisterRequest),ErrorCodeInfo.OK);
    }

    @Operation(summary = "用户名登录")
    @PostMapping("/userLoginByUserName")
    public ResultBean<Boolean> loginByUserName(@RequestBody @Valid LoginByUserNameRequest loginByUserNameRequest){
        return ResultBean.restResult(sysUserService.loginByUserName(loginByUserNameRequest),ErrorCodeInfo.OK);
    }

    @Operation(summary = "手机号登录")
    @PostMapping("/userLoginByPhone")
    public ResultBean<Boolean> loginByPhone(@RequestBody @Valid LoginByPhoneRequest loginByPhoneRequest){
        return ResultBean.restResult(sysUserService.loginByPhone(loginByPhoneRequest),ErrorCodeInfo.OK);
    }

    @Operation(summary = "上传头像")
    @PostMapping("/uploadHead")
    public ResultBean<SysAttachment> uploadHead(@RequestParam MultipartFile file) {
        return ResultBean.restResult(sysUserService.uploadHead(file), ErrorCodeInfo.OK);
    }
}
